#include <REGX52.H>
/**
 * 两个按钮，一个增加闪烁频率，一个减少闪烁频率
 */

sbit BTN_1 = P2 ^ 3;
sbit BTN_2 = P3 ^ 7;
sbit LED = P3 ^ 1;

unsigned int step = 100;
unsigned int frequency = 200;
unsigned int count = 0;

#define COUNT_MAX 10

void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}

void main()
{
    LED = 1;
    while (1)
    {
        delay_ms(frequency);
        LED = ~LED;

        if (BTN_1 == 0)
        {
            if (count < COUNT_MAX)
            {
                count++;
            }
            else
            {
                frequency += step;
                count = 0;
            }
        }

        // if (BTN_2 == 0)
        // {
        //     while (BTN_2 == 0)
        //     {
        //     }

        //     frequency -= step;
        // }
    }
}